<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('抽奖用户列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
	<div class="row">
		<div class="col-sm-12 search-collapse">
			<form id="lottery-form">
				<div class="select-list">
					<ul>
						<li>
							姓名：<input type="text" name="psnName"/>
						</li>
						<li>
							联系电话：<input type="text" name="tel"/>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()" id="btnSearch"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>

		<div class="btn-group-sm" id="toolbar" role="group">
			<a class="btn btn-success" onclick="$.operate.add()">
				<i class="fa fa-plus"></i> 新增
			</a>
			<a class="btn btn-warning" onclick="$.table.exportExcel()">
				<i class="fa fa-download"></i> 导出
			</a>
		</div>

		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table-lotteryUser"></table>
		</div>
	</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	var prefix = ctx + "biz/lotteryUser";

	$(function() {
		var options = {
			id: "bootstrap-table-lotteryUser",
			url: prefix + "/list",
			createUrl: prefix + "/add",
			updateUrl: prefix + "/edit/{id}",
			removeUrl: prefix + "/remove",
			exportUrl: prefix + "/export",
			sortName: null,
			sortOrder: "desc",
			modalName: "用户",
			columns: [
				/*{
                    field: 'lotteryId',
                    title: '抽奖活动ID'
                },*/
				{
					field: 'psnName',
					title: '姓名',
					sortable: true
				},
				{
					field: 'tel',
					title: '联系电话',
					sortable: true
				},
				{
					field: 'sex',
					title: '性别',
					sortable: true,
					formatter: function(value, row, index) {
						if (!row.sex) {
							return '-';
						} else {
							return row.sex == '0' ? '男' : '女';
						}
					}
				},
				{
					field: 'recAddr',
					title: '收货地址',
					sortable: true
				},
				{
					field: 'userId',
					title: '是否关联微信用户',
					sortable: true,
					formatter: function(value, row, index) {
						return row.userId ? '<span style="color: red;">是</span>' : '否';
					}
				},
				{
					field: 'crteTime',
					title: '创建时间',
					sortable: true
				},
				{
					field: 'crterName',
					title: '创建人',
					sortable: true
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.lotteryUserId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						if (row.userId) {
							actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="wechatInfo(\'' + row.userId + '\')"><i class="fa fa-book"></i>查看绑定信息</a> ');
							actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="removeWechatInfo(\'' + row.lotteryUserId + '\')"><i class="fa fa-minus"></i>解除绑定</a> ');
						}
						actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.lotteryUserId + '\')"><i class="fa fa-remove"></i>删除</a> ');
						return actions.join('');
					}
				}]
		};
		$.table.init(options);
	});

	function wechatInfo(userId) {
		var url = prefix + '/wechatInfo/' + userId;
		$.modal.open("查看绑定微信信息", url, '1200', '700');
	}
	function removeWechatInfo(lotteryUserId) {
		$.modal.confirm('解除绑定信息后，此用户的抽奖信息将和微信使用人失去关联，确认解绑？', function() {
			var config = {
				url: "/biz/lotteryUser/removeBind",
				type: "post",
				dataType: "json",
				data: { "lotteryUserId": lotteryUserId },
				beforeSend: function () {
					$.modal.loading("正在处理中，请稍候...");
				},
				success: function(result) {
					$.modal.closeLoading();
					if (result.code == 0) {
						$.modal.msgSuccess(result.msg);
					} else {
						$.modal.alertError(result.msg);
					}
					$("#btnSearch").click();
				}
			};
			$.ajax(config)
		});
	}
</script>
</body>
</html>